<?php 
	$addParams = array(
					'url' 		  => APP_ROOT.'/new-patients', 
					'titleHead'   => 'Create New Patient',
					'widthParam'  => 750, 
					'heightParam' => 420
				);
	$add = htmlentities(json_encode($addParams));

	//search filter submit
	$obj = new Patient();
	if($_SERVER['REQUEST_METHOD'] == "POST"){
		if(isset($_POST['inactive']) && $_POST['inactive'] == 1){
			$obj->filter = "patient.active <= 1";
		}else{
			$obj->filter = "patient.active = 1";
		}

		if(isset($_POST['searchby']) && !empty($_POST['searchby']) && !empty($_POST['keyword'])){
			$obj->addFilter("patient.".$_POST['searchby']." LIKE '%".$_POST['keyword']."%'");
		}
	}

	//if not super administrator, filter results to all patients of this user
	if($_SESSION['user']['user_type_id'] != CONST_SUPER_ADMIN_TYPE){
		$obj->AddJoin("LEFT JOIN", "user_patient AS up", "patient.id = up.patient_id", "up.user_id");

		if(!empty($_SESSION['user']['user_id'])){
			$obj->addFilter("up.user_id = ".$_SESSION['user']['user_id']);
		}
	}

	//view all using pagination
	$query 		= $obj->FormQuery();
	$cntrows	= $obj->Count();

	//form pagination
	$rowcntPerPage  = CONST_PAGE_ROW_COUNT;
	$listObj = new Pagination(
				$query,				//query resultset
				$rowcntPerPage,		//max # of rows displayed
				'page',				//pagination variable used in GET or POST
				5					//number of links displayed in getPageNav
			);
 ?>